﻿/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef SHARED_BINARY_BYTEBUFFEREXCEPTION_H_
#define SHARED_BINARY_BYTEBUFFEREXCEPTION_H_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <cstddef>
#include <cstdint>
#include <string>
#include "Shared/Exception.h"


namespace Shared {
namespace Binary {

    class ByteBufferException: public Exception
    {
    public:
        ByteBufferException(bool add, ::std::size_t pos,
            ::std::size_t size, ::std::size_t esize)
            : _add(add), _pos(pos), _esize(esize), _size(size)
        {
            printPosError();
        }

        void printPosError() const;

        const char* what(void) const throw ();

    private:
        bool            _add;       /* 是否在添加数据 */
        std::size_t     _pos;       /* 操作的索引位置 */
        std::size_t     _size;      /* 当前缓存大小 */
        std::size_t     _esize;     /* 操作的大小 */

        std::string     _what;
    };

    inline const char *ByteBufferException::what() const throw()
    {
        return _what.c_str();
    }
}}

#endif // SHARED_BINARY_BYTEBUFFEREXCEPTION_H_
